package com.situ.mall.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.common.ServerResponse;
import com.situ.mall.entity.Product;
import com.situ.mall.service.IProductService;
import com.situ.mall.entity.Product;


@Controller
@RequestMapping("/product")
public class ProductController {
	@Autowired
	private IProductService productService;

	@RequestMapping("/getProductListPage")
	private String getProductListPage() {
		return "product_list";
	}
	
	
	
	@RequestMapping("/pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page,Integer limit,Product product) {
		return productService.pageList(page,limit,product);
	}
	
	@RequestMapping("/deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id) {
		return productService.deleteById(id);
	}
	
	@RequestMapping("/getInsertPage")
	public String getInsertPage() {
		return "product_insert";
	}
	
	@RequestMapping("/insert")
	@ResponseBody
	public ServerResponse insert(Product product) {
		return productService.insert(product);
	}
	
	@RequestMapping("/getUpdatePage")
	public String getUpdatePage(Integer id, Model model) {
		Product product = productService.selectById(id);
		model.addAttribute("product", product);
		return "product_update";
	}
	
	@RequestMapping("/update")
	@ResponseBody
	public ServerResponse update(Product product) {
		return productService.update(product);
	}
	
	
	
	
	
}
